package cn.wolfcode.wms.web.controller;


import cn.wolfcode.wms.domain.OrderBill;
import cn.wolfcode.wms.domain.Supplier;
import cn.wolfcode.wms.query.OrderBillQueryObject;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IOrderBillService;
import cn.wolfcode.wms.service.ISupplierService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("orderBill")
public class OrderBillController {
    @Autowired
    private IOrderBillService orderBillService;
    @Autowired
    private ISupplierService supplierService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") OrderBillQueryObject qo, Model model){
        PageResult pageResult = orderBillService.queryResult(qo);
        model.addAttribute("result",pageResult);
        model.addAttribute("suppliers",supplierService.selectList());
        return "orderbill/list";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){

        if (id != null) {
            model.addAttribute("entity",orderBillService.get(id));

        }
        model.addAttribute("suppliers",supplierService.selectList());
        return "orderbill/input";
    }
    @RequestMapping("audit")
    @ResponseBody
    public Object audit(Long orditId){

        //调用审核方法
        orderBillService.audit(orditId);

        return null;
    }
    @RequestMapping("view")
    public String view(Model model,Long id){

        if (id != null) {
            model.addAttribute("entity",orderBillService.get(id));
        }
            OrderBill orderBill = orderBillService.get(id);
            Supplier supplier = orderBill.getSupplier();
        model.addAttribute("supplier",supplier);
        return "orderbill/view";
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){

        orderBillService.delete(id);

        return new JSONResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(OrderBill d){

        orderBillService.saveOrUpdate(d);

        return new JSONResult();
    }

}
